package com.woniuxy01;

import java.util.Scanner;

public class Test05 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        //系统随机数
        int random = (int) (Math.random() * 100);
        System.out.println("random:"+random);
        int num;
        int count=1;
        //true猜对了，false猜错了
        boolean flag=false;
        do{
            System.out.println("输入你猜的数字");
            num=scanner.nextInt();
            if(num>random){
                System.out.println("猜大了");
            }else if(num<random){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                flag=true;
                break;
            }

            if (count<5) {
                System.out.println("还有"+(5-count)+"次几乎");
            }
            count++;
        }while (count<=5);
        //猜对了，游戏结束
        //次机会用完了，游戏结束
        if (flag) {
            System.out.println("程序结束");
        } else {
            System.out.println("5次机会用完了，游戏结束");
        }
    }
}
